package com.blb.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.blb.entity.Order;
import com.blb.entity.Par;
import com.blb.entity.Product;
import com.blb.entity.User;
import com.blb.service.*;
import com.blb.utils.ShiroUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@RequestMapping("/index")
@Controller
public class IndexController {

    //通过session获取当前的公司ID
    private static User user;

    @Resource
    private IndexService indexService;

    @Resource
    private IParService parService;

    @Resource
    private IOrderService orderService;

    @Resource
    private IProductService productService;

    /**
     * 获取公司待审核的数量
     * @return
     */
    @ResponseBody
    @RequestMapping("clientAudit")
    public int getClientAudit(){
        user= ShiroUtils.getUser();
        return parService.count(new QueryWrapper<Par>().eq("t_par_com_b",user.getCompanyId()).eq("t_par_status2","未查看"));
    }

    /**
     * 获取公司待审核的数量
     * @return
     */
    @ResponseBody
    @RequestMapping("apply")
    public int getApply(){
        user= ShiroUtils.getUser();
        return parService.count(new QueryWrapper<Par>().eq("t_par_com_a",user.getCompanyId()).eq("t_par_status","已申请"));
    }

    /**
     * 获取订单列表中状态等于2的的数量
     * @return
     */
    @ResponseBody
    @RequestMapping("OrderList")
    public int getOrderList(){
        return orderService.count(user.getCompanyId(),null,null,"2");
    }

    /**
     * 获取订单列表中状态等于5的的数量
     * @return
     */
    @ResponseBody
    @RequestMapping("OrderSheet")
    public int getOrderSheet(){
        return orderService.count(new QueryWrapper<Order>().eq("product_status","5").eq("supplier_id",user.getCompanyId()));
    }

    /**
     * 获取待生产的订单
     * @return
     */
    @ResponseBody
    @RequestMapping("production")
    public int getProduction(){
        return orderService.count(new QueryWrapper<Order>().eq("product_status","6").eq("supplier_id",user.getCompanyId()).isNull("laser_code"));
    }

    /**
     * 获取待出库的数量
     * @return
     */
    @ResponseBody
    @RequestMapping("handoverList")
    public int getHandoverList(){
        return indexService.getHandoverList(user.getCompanyId());
    }

    /**
     * 获取商品审核的数量
     * @return
     */
    @ResponseBody
    @RequestMapping("commodityAudit")
    public int getCommodityAudit(){
        return productService.count(new QueryWrapper<Product>().eq("a_status","-1").eq("company_id",user.getCompanyId()));
    }

    @ResponseBody
    @RequestMapping("purchaseAudit")
    public int getPurchaseAudit(){
        return orderService.count(new QueryWrapper<Order>().eq("order_status","3").eq("supplier_id",user.getCompanyId()));
    }

    @ResponseBody
    @RequestMapping("StockWarning")
    public int getStockWarning(){
        return indexService.getStockWarning(user.getCompanyId());
    }

}
